package com.ydh.live.data.bus;

import android.annotation.SuppressLint;
import android.arch.lifecycle.Observer;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.TextView;

import com.ydh.live.data.bus.util.v1.LiveDataBus;
import com.ydh.live.data.bus.util.v2.LiveEventBus;

/**
 * 数据展示类
 *
 * @author 13001
 */
public class DisplayDataActivity extends AppCompatActivity {

    private static final String TAG = DisplayDataActivity.class.getSimpleName();

    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_display_data);

        tv = findViewById(R.id.tv_display_data);

        LiveDataBus.get()
                .with("display_data", String.class)
                .observe(this, new Observer<String>() {
                    @SuppressLint("SetTextI18n")
                    @Override
                    public void onChanged(@Nullable String s) {
                        tv.setText("LiveData 数据展示：" + s);
                        Log.e(TAG, "onChanged:   数据:" + s + "   线程:" + Thread.currentThread().getName());
                    }
                });

        LiveEventBus.get()
                .with("display_data", String.class)
                .observeSticky(this, new Observer<String>() {
                    @SuppressLint("SetTextI18n")
                    @Override
                    public void onChanged(@Nullable String s) {
                        tv.setText("LiveEvent 数据展示：" + s);
                        Log.e(TAG, "onChanged:   数据:" + s + "   线程:" + Thread.currentThread().getName());
                    }
                });

    }

}